﻿
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WinFormsApp1.Common;
using static WinFormsApp1.Leo.ClientserShow;

namespace WinFormsApp1.Leo
{
    public partial class ClientserShow : Form
    {
        public ClientserShow()
        {
            InitializeComponent();
        }




        //客户列表显示
        private async void ClientserShow_Load(object sender, EventArgs e)
        {
            var items = await HttpClientHelper.RequestUrl<string, ApiResult<List<ClientsShows>>>(URLCommon.Url2, "/WeekListOne_Leo/GetClientsShow", HttpClientHelper.MethodType.GET, default);
            this.dataGridView1.DataSource= null;
            this.dataGridView1.DataSource = items.Data;

        }

        //状态显示判断
        private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (e.ColumnIndex == dataGridView1.Columns["状态"].Index && e.Value != null)
            {
                if (e.Value.ToString() == "True")
                {
                    e.Value = "正在运行";
                    e.FormattingApplied = true;
                }
                else
                {
                    e.Value = "已停运";
                    e.FormattingApplied = false;
                }
            }
        }

        public record ClientserDel(int CustomerId);
        //删除
        private async void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == dataGridView1.Columns["操作"].Index)
            {
                var wins = (int)e.RowIndex;
                if (wins >= 0)
                {
                    int CustomerId = Convert.ToInt32(dataGridView1.Rows[wins].Cells["序列"].Value);

                    ClientserDel clientserDel = new(CustomerId);

                    var items = await HttpClientHelper.RequestUrl<ClientserDel, ApiResult<List<ClientserDelser>>>(URLCommon.Url1, "/WorkList01_leo/GetClientsDel", HttpClientHelper.MethodType.POST, clientserDel);

                    if (items.Code == 1)
                    {
                        MessageBox.Show("删除成功");
                    }
                    else
                    {
                        MessageBox.Show("删除失败");
                    }


                }
            }
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }
    }
}
